package com.itheima.homework.demo1;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class Demo1 {
    private static ArrayList<String> list =new ArrayList<>();
    private static TreeSet<String> set=new TreeSet<>();
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要统计文件夹的路径:");
        String s=sc.next();
        File f=new File(s);
        if (f.exists()&&f.isDirectory()){
            getFile(f);
            for (String s1 : set) {
                int count=0;
                for (String s2 : list) {
                    if(s1.equals(s2)){
                        count++;
                    }
                }
                System.out.println(s1+"类型的文件有"+count+"个");
            }
        }else{
            System.out.println("输入的路径不合法");
        }
    }
    public static  void getFile(File file){
        File[] files = file.listFiles();
        if(files!=null){
            for (File file1 : files) {
                if(file1.isFile()) {
                    String name = file1.getName();
                    String[] names = name.split("\\.");
                    list.add(names[names.length-1]);
                    set.add(names[names.length-1]);
                }else{
                    getFile(file1);
                }

            }

        }

       }



        }



